package com.my.home.common.Base;

import java.util.HashMap;
import java.util.Map;

/**
 * Json返回通用类
 * Created by Al Sah-him on 2018/5/28.
 */
public class RespJson {
    private static final String ERROR_CODE="errcode";
    private static final String ERROR_MESSAGE="errmsg";

    private static Map<String,Object> map=new HashMap<>();

    /**
     * 成功无返回值
     * @return
     */
    public static Map<String,Object> success(){
        return success(null,null);
    }


    /**
     * 成功无返回值
     * @return
     */
    public static Map<String,Object> success(String key,Object val){
//        RespJson json=new RespJson();
        map.put(ERROR_CODE,"0");
        map.put(ERROR_MESSAGE,"success");
        if(key!=null){
            map.put(key,val);
        }
        return map;
    }


    /**
     * 自定义code失败
     * @return
     */
    public static Map<String,Object> failure(Integer code,String msg){
//        RespJson json=new RespJson();
        map.put(ERROR_CODE,code);
        map.put(ERROR_MESSAGE,msg);
        return map;
    }

    /**
     * 失败
     * @return
     */
    public static Map<String,Object> failure(String msg){
//        RespJson json=new RespJson();
        return failure(-1,msg);
    }


}
